package indi.zhifa.recipe.bailan.framework.auth.entity.dto;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.SM2;

/**
 * Description: 
 * @Copyright: Copyright (c) 2020-2028 北京华咨电力科技发展有限公司 All rights reserved.
 * @author: 褚智勇(hataksumo@163.com)
 * @date:  2022/4/24 16:50
 */

public class Sm2Encrypt {

    private final SM2 mSm2;

    public Sm2Encrypt(){
        mSm2 = new SM2();
    }

    public Sm2Encrypt(String pPrivateKey, String pPublicKey){
        mSm2 = new SM2(pPrivateKey,pPublicKey);
    }

    public String decode(String pText){
        String decryptStr = mSm2.decryptStr(pText,KeyType.PrivateKey);
        return decryptStr;
    }

    public String encode(String pText){
        String encryptStr = mSm2.encryptBcd(pText, KeyType.PublicKey);
        return encryptStr;
    }

    public String getPublicKey(){
        return mSm2.getPublicKeyBase64();
    }

    public String getPrivateKey(){
        return mSm2.getPrivateKeyBase64();
    }


}
